package ar.uba.dc.tl.mylanga.inputhandler;

import java.io.PushbackReader;
import java.io.StringReader;
import java.util.List;

public class CommandLineInputHandler extends InputHandler {

	public CommandLineInputHandler(Input input) {
		super(input);
	}

	@Override
	public void checkArguments() {
		List<String> arguments = this.getArguments();

		if (arguments == null || arguments.size() < 2) {
			throw new RuntimeException("invalid arguments");
		}
	}

	private String getContents() {
		this.checkArguments();

		List<String> arguments = this.getArguments();
		StringBuilder contents = new StringBuilder(1024);

		for (int index = 1; index < arguments.size(); ++index) {
			contents.append(arguments.get(index));
			contents.append(' ');
		}

		return contents.toString();
	}

	@Override
	public PushbackReader getReader() {
		String contents = this.getContents();
		PushbackReader reader = new PushbackReader(new StringReader(contents), InputHandler.PUSH_BACK_SIZE);

		return reader;
	}
}
